private function IniCountKeys(unit) result(count)
count Key-Val pair in a file
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
integer(kind=short),
|
intent(in) |
|
|
:: |
unit |
|
Return Value
integer(kind=long)
Variables
Type |
Visibility | Attributes |
|
Name |
| Initial | |
integer(kind=long),
|
public |
|
:: |
eqPos |
|
|
|
integer(kind=long),
|
public |
|
:: |
hashPos |
|
|
|
character(len=stringLen),
|
public |
|
:: |
inLine |
|
|
|
integer(kind=short),
|
public |
|
:: |
ios |
|
|
|
Source Code
FUNCTION IniCountKeys &
( unit ) &
RESULT (count)
IMPLICIT NONE
! function arguments
! Scalar arguments with intent(in):
INTEGER (KIND = short), INTENT(in) :: unit
!Local scalar:
INTEGER (KIND = long) :: eqPos
INTEGER (KIND = long) :: hashPos
INTEGER (KIND = long) :: count
CHARACTER (LEN = stringLen ) :: inLine
INTEGER (KIND = short) :: ios
!------------end of declaration------------------------------------------------
REWIND (unit)
ios = 0
count = 0
DO
READ (unit,'(a)',IOSTAT = ios) inLine
IF (ios < 0 ) THEN
EXIT
END IF
inLine = TRIM ( ADJUSTL ( inLine ) )
!search for key
!remove comments
hashPos = SCAN ( inLine , '#' )
IF (hashPos /= 0) THEN
inline = inline (1 : hashPos-1)
END IF
eqPos = SCAN ( inLine , '=' )
IF ( eqPos /= 0 .AND. inLine(1:1) /= '#' ) THEN
count = count + 1
END IF
END DO
END FUNCTION IniCountKeys